const Core = require('@alicloud/pop-core')
const client = new Core({
    accessKeyId: 'LTAI5tC87KBiezUnErmYVH6E',
    accessKeySecret: 'Rlbz48o1r0Gv1noKlX7F5tOOk8SQrJ',
    endpoint: 'https://dysmsapi.aliyuncs.com',
    apiVersion: '2017-05-25'
})
const random = () => {
    return  Math.floor(Math.random() * 9000) + 1000
}
let yancode=random()
const params = {
    PhoneNumbers: "",
    SignName: "小尤",
    TemplateCode: "SMS_464210238",  //小尤1
    TemplateParam: `{\"code\":\"${yancode}\"}`
}

const requestOption = {
    method: 'POST',
    formatParams: false
}

const sendCode = (phoneNum) => {
    params.PhoneNumbers = phoneNum
    return new Promise((resolve, reject) => {
        client.request('SendSms', params, requestOption).then((result) => {
            resolve(JSON.stringify(result))
        }, (err) => {
            reject(err)
        })
    })
}
console.log("q12")

module.exports = {sendCode,yancode}
